package com.lly;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet("/servletA")
public class ServletA extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.请求域
        req.setAttribute("reqyu","reqyu");
        //2.会话域
        HttpSession session = req.getSession();
        session.setAttribute("session","session");
        //3.应用域
        ServletContext application = req.getServletContext();
        application.setAttribute("application","application");


        //获取请求域的数据
        String reqyu = (String) req.getAttribute("reqyu");
        System.out.println(reqyu);

        //进行请求转发
        req.getRequestDispatcher("servletB").forward(req,resp);
    }
}
